package com.deli.utils;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.xml.rpc.ParameterMode;

public class GetUserInfoUtil {
    public static String getUserInfo(String workCode) {
        String endpoint = "http://116.62.118.202//services/HrmService";
        Service service = new Service();
        Call call = null;
        try {
            call = (Call) service.createCall();
        } catch (Exception e) {
            System.out.print("callfalse");
        }
        call.setTargetEndpointAddress(endpoint);
        // 调用的方法名
        call.setOperationName("getHrmUserInfoXML");
        // 设置参数名
        call.addParameter("in0", // 参数名
                XMLType.XSD_STRING, // 参数类型:String
                ParameterMode.IN); // 参数模式：'IN' or 'OUT'
        call.addParameter("in1", XMLType.XSD_STRING, ParameterMode.IN);
        call.addParameter("in2", XMLType.XSD_STRING, ParameterMode.IN);
        call.addParameter("in3", XMLType.XSD_STRING, ParameterMode.IN);
        call.addParameter("in4", XMLType.XSD_STRING, ParameterMode.IN);
        call.addParameter("in5", XMLType.XSD_STRING, ParameterMode.IN);
        call.setReturnClass(String.class); // 返回值类型：String
        String userInfo = null;
        try {
            userInfo = (String) call.invoke(new Object[] { "", workCode, "", "", "", "" });

        } catch (Exception e) {
            System.out.print( "callfalse");
        }finally {
            return userInfo;
        }
    }
    public static String getWorkCode(HttpServletRequest request) {
        String workCode="";
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals("username")) {
                workCode = cookie.getValue();
            }
        }
        return workCode;
    }
}
